package com.asen.commons.core.jdbc.dao;

import com.asen.commons.core.jdbc.Jdbc;
import com.asen.commons.core.meta.dao.Condition;

import java.util.List;
import java.util.Map;

/**
 * 数据操作DAO
 *
 * @author Gary
 * @version 1.0
 * @date 2018-11-16
 */
public interface Dao {

    /**
     * 新增
     *
     * @param modelType
     * @param model
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> int add(Class<T> modelType, T model) throws Exception;

    /**
     * 更新
     *
     * @param modelType
     * @param model
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> int update(Class<T> modelType, T model) throws Exception;

    /**
     * 根据whereFields条件更新
     *
     * @param modelType
     * @param model
     * @param whereFields
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> int updateBy(Class<T> modelType, T model, String... whereFields) throws Exception;

    /**
     * 根据condition条件更新
     *
     * @param model
     * @param condition
     * @throws Exception
     */
    <T> int updateBy(Class<T> modelType, T model, Condition condition) throws Exception;

    /**
     * 部分更新
     *
     * @param modelType
     * @param model
     * @param partialFields
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> int updatePartial(Class<T> modelType, T model, String... partialFields) throws Exception;

    /**
     * 根据whereFields条件部分更新
     *
     * @param modelType
     * @param model
     * @param partialFields
     * @param whereFields
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> int updatePartialBy(Class<T> modelType, T model, String[] partialFields, String... whereFields) throws Exception;

    /**
     * 根据whereFields条件部分更新
     *
     * @param modelType
     * @param model
     * @param partialFields
     * @param whereFields
     * @param ignoreFields
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> int updatePartialBy(Class<T> modelType, T model, String[] partialFields, String[] whereFields, String... ignoreFields) throws Exception;

    /**
     * 物理删除
     *
     * @param modelType
     * @param id
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> int delete(Class<T> modelType, Long id) throws Exception;

    /**
     * 物理删除
     *
     * @param modelType
     * @param model
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> int delete(Class<T> modelType, T model) throws Exception;

    /**
     * 根据whereFields条件物理删除
     *
     * @param modelType
     * @param model
     * @param whereFields
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> int deleteBy(Class<T> modelType, T model, String... whereFields) throws Exception;

    /**
     * 删除
     *
     * @param modelType
     * @param condition
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> int deleteBy(Class<T> modelType, Condition condition) throws Exception;

    /**
     * 根据ID获取对象
     *
     * @param modelType
     * @param id
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> T getValue(Class<T> modelType, Long id) throws Exception;

    /**
     * 获取所有
     *
     * @param modelType
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> List<T> getAll(Class<T> modelType) throws Exception;

    /**
     * 分布查询
     *
     * @param modelType
     * @param pageNum
     * @param pageSize
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> List<T> getAll(Class<T> modelType, int pageNum, int pageSize) throws Exception;

    /**
     * 根据条件查询
     *
     * @param modelType
     * @param condition
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> List<T> getList(Class<T> modelType, Condition condition) throws Exception;

    /**
     * 查询所有记录数
     *
     * @param modelType
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> int getCount(Class<T> modelType) throws Exception;

    /**
     * 查询记录数
     *
     * @param modelType
     * @param condition
     * @param <T>
     * @return
     * @throws Exception
     */
    <T> int getCount(Class<T> modelType, Condition condition) throws Exception;

    /**
     * 执行SQL插入或更新脚本
     *
     * @param sql
     * @return
     * @throws Exception
     */
    int execSql(String sql) throws Exception;

    /**
     * 执行SQL查询
     *
     * @param sql
     * @return
     * @throws Exception
     */
    List<Map<String, Object>> query(String sql) throws Exception;

    /**
     * jdbc
     *
     * @return
     */
    Jdbc getJdbc();

    /**
     * jdbc
     *
     * @param jdbc
     */
    void setJdbc(Jdbc jdbc);
}
